package com.mec.web.y2012.coreservlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

@WebServlet("/CollectionsServlet")
public class CollectionsServlet extends HttpServlet {
	
	private static final long serialVersionUID = 5888269690982524129L;
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		String[] firstNames = {"Bill", "Scott", "Larry"};
		List<String> lastNames = new ArrayList<String>();
		lastNames.add("Ellison");
		lastNames.add("Gates");
		lastNames.add("McNealy");
		//
		Map<String, String> companyNames = new HashMap<String, String>();
		companyNames.put("Ellison", "Sun");
		companyNames.put("Gates", "Oracle");
		companyNames.put("McNealy", "Microsoft");
		
		//
		req.setAttribute("first", firstNames);
		req.setAttribute("last", lastNames);
		req.setAttribute("company", companyNames);
		
		//
		RequestDispatcher dispatcher = req.getRequestDispatcher("el/collections.jsp");
		dispatcher.forward(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doGet(req, resp);
	}


	private static final Logger logger = 
			Logger.getLogger(CollectionsServlet.class);
}
